package com.tenglong.iservice.controller;

import com.tenglong.iservice.pojo.Service;
import com.tenglong.iservice.service.IserviceService;
import com.tenglong.util.BaseResult;
import org.apache.commons.codec.binary.Base32;
import org.codehaus.jackson.map.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Chen-D.W on 2018/5/25.
 */
@Controller
@RequestMapping("/rest")
public class ServController {

    @Autowired
    private IserviceService iserviceService;

    /**
     * @Author 陈董伟  edu.zzuli
     * Date 2018/5/25 20:24
     * @Descrintion 添加和编辑服务
     */
    @RequestMapping("/addservice")
    @ResponseBody
    public BaseResult addService(Service service){
        BaseResult result;
        if (service.getId()!=null&&service.getId()!=""){
            result=iserviceService.editService(service);
            return result;
        }
        result=iserviceService.addService(service);
        return result;
    }
    /**
     * @Author 陈董伟  edu.zzuli
     * Date 2018/5/25 20:24
     * @Descrintion 删除操作
     */
    @RequestMapping("/delservice")
    @ResponseBody
    public BaseResult delService(@RequestParam("id") String id){
       BaseResult result= iserviceService.removeServiceById(id);
       return result;
    }
    /**
     * @Author 陈董伟  edu.zzuli
     * Date 2018/5/26 20:13
     * @Descrintion 根据用户id获取服务列表
     */
    @RequestMapping("/getservice")
    @ResponseBody
    public BaseResult getserviceByuseridid(@RequestParam("id") String userid){
        BaseResult result=iserviceService.getUserServiceById(userid,1L);
        return result;
    }
    /**
     * @Author chendongwei
     * Date 2018-05-28 19:19
     * @Descrintion 根据服务id获取服务详情
     */
    @RequestMapping("/getservicebyid")
    @ResponseBody
    public BaseResult getserviceByid(@RequestParam("id")String id){
        BaseResult result=iserviceService.getUserServiceById(id,2L);
        return result;
    }

}
